package com.example.tree.heap;

import java.util.PriorityQueue;
import java.util.Queue;

public class TestHeap {
    public static void main(String[] args) {
        Queue<Integer> minHeap = new PriorityQueue<>();
        minHeap.add(3);
        minHeap.add(7);
        minHeap.add(1);
        while (!minHeap.isEmpty()) {
            System.out.println(minHeap.poll());
        }


        Queue<People> maxHeap = new PriorityQueue<>(3,
                (o1, o2) -> {
                    if (o1.age - o2.age == 0) {
                        return o1.length - o2.length;
                    }
                    return o1.age - o2.age;
                });
        maxHeap.offer(new People("zhangsan1", 18, 156));
        maxHeap.offer(new People("zhangsan2", 15, 156));
        maxHeap.add(new People("zhangsan3", 15, 159));
        maxHeap.add(new People("zhangsan4", 1, 189));
        maxHeap.add(new People("zhangsan5", 2, 176));
        maxHeap.add(new People("zhangsan6", 15, 190));

        while (!maxHeap.isEmpty()) {
            System.out.println(maxHeap.poll());
        }
    }

    private static class People {
        private String name;
        private int age;
        private int length;

        public People(String name, int age, int length) {
            this.name = name;
            this.age = age;
            this.length = length;
        }

        @Override
        public String toString() {
            return "People{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    ", length=" + length +
                    '}';
        }
    }
}
